/*
 * 文 件    名:  BrowsingHistoryImpl.java
 * 创建日期:  2012-10-22上午10:56:49
 * 版          权:  Epro Technologies Co., Ltd. Copyright 2011-2012,  All rights reserved
 * 作          者:  tj072
 */
package com.weipu.common.facade.content.impl;

import java.util.Arrays;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;

import com.weipu.common.facade.content.BaseContentProvider;
import com.weipu.common.facade.content.ContentURI;
import com.weipu.common.util.Logger;

/** 
 * @Description 浏览历史实现类
 * @version [版本号, 2012-10-22]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author tj072
 */
public class BrowsingHistoryImpl extends BaseContentProvider
{
    /**
     * log tag
     */
    private static final String TAG = BrowsingHistoryImpl.class.getName();
    
    /**
     * table name
     */
    private static final String TABLE_NAME = ContentURI.ContentBrowsingHistory.TABLE_NAME;
    
    /**
     * get content type by config
     * @param uri
     * @return
     */
    public String getType(Uri uri)
    {
        return null;
    }
    
    /**
     * add
     * @param uri
     * @param values
     * @return
     */
    public Uri insert(Uri uri, ContentValues values)
    {
        if (Logger.isLog)
        {
            Logger.d(TAG, "enter into insert");
        }
        long rowId = dbWriter.insert(TABLE_NAME, null, values);
        values.put(BaseColumns._ID, rowId);
        if (Logger.isLog)
        {
            Logger.d(TAG, "exit from insert, result " + rowId);
        }
        
        return uri;
    }
    
    /**
     * delete
     */
    public int delete(Uri uri, String selection, String[] selectionArgs)
    {
        if (Logger.isLog)
        {
            Logger.d(TAG,
                "enter into delete, parameter {selection:" + selection + ",args:" + Arrays.toString(selectionArgs)
                    + "}");
        }
        int deleteRow = dbWriter.delete(TABLE_NAME, selection, selectionArgs);
        Logger.d(TAG, "exit from delete, result " + deleteRow);
        return deleteRow;
    }
    
    /**
     * query
     * @param uri
     * @param projection
     * @param selection
     * @param selectionArgs
     * @param sortOrder
     * @return
     */
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
    {
        return dbReader.query(TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
    }
    
    /**
     * update
     * @param uri
     * @param values
     * @param selection
     * @param selectionArgs
     * @return
     */
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)
    {
        if (Logger.isLog)
        {
            Logger.d(TAG, "enter into update");
        }
        int updateRow = dbWriter.update(TABLE_NAME, values, selection, selectionArgs);
        if (Logger.isLog)
        {
            Logger.d(TAG, "exit from update, result " + updateRow);
        }
        return updateRow;
    }
    
}
